package week9;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main5 {
	public static void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		while(true)
		{
			String choice = in.next();
			switch(choice){
				case "Integer":
					System.out.println("Integer Test");
					ArrayListGeneralStack<Integer> inte = new ArrayListGeneralStack<Integer>();
					int x1 = in.nextInt();
					int y1 = in.nextInt();
					for (int i = 0; i < x1; i++) {
						System.out.println("push:"+inte.push(in.nextInt()));
					}
					for (int i = 0; i < y1; i++) {
						System.out.println("pop:"+inte.pop());
					}
					System.out.println(inte.toString());
					int a1=0;
					for (int i = 0; i < x1-y1; i++) {
						a1 = a1 + (int)inte.pop();
					}
					System.out.println("sum="+a1);
					System.out.println(inte.getClass().getInterfaces()[0]);
					break;
				case "Double":
					System.out.println("Double Test");
					ArrayListGeneralStack<Double> dou = new ArrayListGeneralStack<Double>();
					int x2 = in.nextInt();
					int y2 = in.nextInt();
					for (int i = 0; i < x2; i++) {
						System.out.println("push:"+dou.push(in.nextDouble()));
					}
					for (int i = 0; i < y2; i++) {
						System.out.println("pop:"+dou.pop());
					}
					System.out.println(dou.toString());
					double a2=0;
					for (int i = 0; i < x2-y2; i++) {
						a2 = a2 + (double)dou.pop();
					}
					System.out.println("sum="+a2);
					System.out.println(dou.getClass().getInterfaces()[0]);
					break;
				case "Car":
					System.out.println("Car Test");
					ArrayListGeneralStack<Car> cars = new ArrayListGeneralStack<Car>();
					int x3 = in.nextInt();
					int y3 = in.nextInt();
					for (int i = 0; i < x3; i++) {
						Car car = new Car(in.nextInt(),in.next());
						System.out.println("push:"+cars.push(car));
					}
					for (int i = 0; i < y3; i++) {
						System.out.println("pop:"+cars.pop());
					}
					System.out.println(cars);
					for (int i = 0; i < x3-y3; i++) {
						System.out.println(cars.pop().getName());
					}
					System.out.println(cars.getClass().getInterfaces()[0]);
					break;
				default:
					System.exit(0);
					break;
			}
		}
	}
}

interface GeneralStack<T>
{
	public T push(T item);
	public T pop();
	public T peek();
	public boolean empty();
	public int size();
}

class ArrayListGeneralStack<T> implements GeneralStack
{
	List<T> list = new ArrayList<T>();
	public String toString() 
	{
		return list.toString();
	}
	@Override
	public T push(Object item) {
		if(item == null)
			return null;
		list.add((T) item);
		return (T) item;
	}
	@Override
	public T pop() {
		if(list.size() == 0)
			return null;
		return list.remove(list.size()-1);
	}
	@Override
	public T peek() {
		if(size() == 0)
			return null;
		return list.get(list.size()-1);
	}
	@Override
	public boolean empty() {
		return list.isEmpty();
	}
	@Override
	public int size() {
		return list.size();
	}	
}
class Car
{
	private int id; 
	private String name;
	public Car(int id, String name) {
		this.id=id;
		this.name=name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
}